package com.xbongbong.pro.enums;

import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 套餐类型
 * 创建时间 2019/5/6 4:45 PM
 * 修改时间 2019/5/6 4:45 PM
 * @author chy
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum SaasTableCountTypeEnum {

    //crm
    CUSTOMER(XbbRefTypeEnum.CUSTOMER_MANAGEMENT, Arrays.asList(XbbRefTypeEnum.CUSTOMER_MANAGEMENT)),
    SALES_OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY, Arrays.asList(XbbRefTypeEnum.SALES_OPPORTUNITY)),
    CONTACT(XbbRefTypeEnum.CONTACT, Arrays.asList(XbbRefTypeEnum.CONTACT)),
    CONTRACT(XbbRefTypeEnum.CONTRACT, Arrays.asList(XbbRefTypeEnum.CONTRACT)),
    CUSTOMER_COMMUNICATE(XbbRefTypeEnum.CUSTOMER_COMMUNICATE, Arrays.asList(XbbRefTypeEnum.CUSTOMER_COMMUNICATE)),
    REFUND(XbbRefTypeEnum.REFUND, Arrays.asList(XbbRefTypeEnum.REFUND)),
    WORK_REPORT(XbbRefTypeEnum.WORK_REPORT, Arrays.asList(XbbRefTypeEnum.WORK_REPORT, XbbRefTypeEnum.WORKREPORT_DAILY, XbbRefTypeEnum.WORKREPORT_WEEKLY, XbbRefTypeEnum.WORKREPORT_MONTHLY)),
    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER, Arrays.asList(XbbRefTypeEnum.WORK_ORDER)),
    COMMUNICATE_PLAN(XbbRefTypeEnum.COMMUNICATE_PLAN, Arrays.asList(XbbRefTypeEnum.COMMUNICATE_PLAN)),
    QUOTATION(XbbRefTypeEnum.QUOTATION, Arrays.asList(XbbRefTypeEnum.QUOTATION)),


    //jxc
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE, Arrays.asList(XbbRefTypeEnum.RETURNED_PURCHASE)),
    OUTSTOCK(XbbRefTypeEnum.OUTSTOCK, Arrays.asList(XbbRefTypeEnum.OUTSTOCK, XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK, XbbRefTypeEnum.CONTRACT_OUTSTOCK, XbbRefTypeEnum.WORK_ORDER_OUTSTOCK, XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK, XbbRefTypeEnum.OTHER_OUTSTOCK)),
    BOM_BILL(XbbRefTypeEnum.BOM_BILL, Arrays.asList(XbbRefTypeEnum.BOM_BILL)),
    SUPPLIER_COMMUNICATE(XbbRefTypeEnum.SUPPLIER_COMMUNICATE, Arrays.asList(XbbRefTypeEnum.SUPPLIER_COMMUNICATE)),
    PRODUCTION_ORDER(XbbRefTypeEnum.PRODUCTION_ORDER, Arrays.asList(XbbRefTypeEnum.PRODUCTION_ORDER)),
    INVENTORY(XbbRefTypeEnum.INVENTORY, Arrays.asList(XbbRefTypeEnum.INVENTORY)),
    TRANSFER(XbbRefTypeEnum.TRANSFER, Arrays.asList(XbbRefTypeEnum.TRANSFER)),
    INSTOCK(XbbRefTypeEnum.INSTOCK, Arrays.asList(XbbRefTypeEnum.INSTOCK, XbbRefTypeEnum.PURCHASE_INSTOCK, XbbRefTypeEnum.REFUND_INSTOCK, XbbRefTypeEnum.PRODUCTION_ORDER, XbbRefTypeEnum.OTHER_INSTOCK)),
    PURCHASE(XbbRefTypeEnum.PURCHASE, Arrays.asList(XbbRefTypeEnum.PURCHASE)),
    SUPPLIER(XbbRefTypeEnum.SUPPLIER, Arrays.asList(XbbRefTypeEnum.SUPPLIER)),
    SUPPLIER_CONTACT(XbbRefTypeEnum.SUPPLIER_CONTACT, Arrays.asList(XbbRefTypeEnum.SUPPLIER_CONTACT)),
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE, Arrays.asList(XbbRefTypeEnum.ASSEMBLE)),
    PRODUCT(XbbRefTypeEnum.PRODUCT, Arrays.asList(XbbRefTypeEnum.PRODUCT)),

    //资金
    PAYMENT(XbbRefTypeEnum.PAYMENT, Arrays.asList(XbbRefTypeEnum.PAYMENT)),
    //有七种类型回款单（预收款余额列表也归属为回款单）
    PAYMENT_SHEET(XbbRefTypeEnum.PAYMENT_SHEET, Arrays.asList(XbbRefTypeEnum.PAYMENT_SHEET, XbbRefTypeEnum.WRITE_OFF_PREPAYMENT, XbbRefTypeEnum.PREPAYMENT, XbbRefTypeEnum.RED_PAYMENT_SHEET, XbbRefTypeEnum.RED_WRITE_OFF_PREPAYMENT, XbbRefTypeEnum.RED_WRITE_OFF_BALANCE, XbbRefTypeEnum.RED_PREPAYMENT, XbbRefTypeEnum.BAD_DEBT, XbbRefTypeEnum.PREPAYMENT_BALANCE)),
    PAY_PLAN(XbbRefTypeEnum.PAY_PLAN, Arrays.asList(XbbRefTypeEnum.PAY_PLAN)),
    //有七种类型付款单（预付款余额列表也归属为付款单）
    PAY_SHEET(XbbRefTypeEnum.PAY_SHEET, Arrays.asList(XbbRefTypeEnum.PAY_SHEET, XbbRefTypeEnum.WRITE_OFF_PREPAY, XbbRefTypeEnum.PREPAY, XbbRefTypeEnum.RED_WRITE_OFF_PAY, XbbRefTypeEnum.RED_WRITE_OFF_PREPAY, XbbRefTypeEnum.RED_PREPAY, XbbRefTypeEnum.BAD_PAY, XbbRefTypeEnum.PREPAY_BALANCE)),
    INVOICE(XbbRefTypeEnum.INVOICE, Arrays.asList(XbbRefTypeEnum.INVOICE)),
    PURCHASE_INVOICE(XbbRefTypeEnum.PURCHASE_INVOICE, Arrays.asList(XbbRefTypeEnum.PURCHASE_INVOICE)),

    OTHER_INCOME(XbbRefTypeEnum.OTHER_INCOME, Arrays.asList(XbbRefTypeEnum.OTHER_INCOME, XbbRefTypeEnum.RED_OTHER_INCOME)),
    OTHER_EXPENSE(XbbRefTypeEnum.OTHER_EXPENSE, Arrays.asList(XbbRefTypeEnum.OTHER_EXPENSE, XbbRefTypeEnum.RED_OTHER_EXPENSE)),
    FUND_TRANSFER(XbbRefTypeEnum.FUND_TRANSFER, Arrays.asList(XbbRefTypeEnum.FUND_TRANSFER)),
    CLUE(XbbRefTypeEnum.CLUE, Arrays.asList(XbbRefTypeEnum.CLUE)),
    KNOWLEDGE_BASE(XbbRefTypeEnum.KNOWLEDGE_BASE, Arrays.asList(XbbRefTypeEnum.KNOWLEDGE_BASE)),


    UNKNOWN(XbbRefTypeEnum.UNKNOWN, Arrays.asList()),
    ;

    /**
     * 指向枚举
     */
    private XbbRefTypeEnum xbbRefTypeEnum;
    /**
     * xbbRefTypeEnums中所有的枚举都指向xbbRefTypeEnum
     */
    private List<XbbRefTypeEnum> xbbRefTypeEnums;

    SaasTableCountTypeEnum(XbbRefTypeEnum xbbRefTypeEnum, List<XbbRefTypeEnum> xbbRefTypeEnums) {
        this.xbbRefTypeEnum = xbbRefTypeEnum;
        this.xbbRefTypeEnums = xbbRefTypeEnums;
    }

    public static SaasTableCountTypeEnum getByType(Integer xbbRefType) {
        for (SaasTableCountTypeEnum cache : values()) {
            List<XbbRefTypeEnum> xbbRefTypeEnums = cache.getXbbRefTypeEnums();
            for (XbbRefTypeEnum xbbRefTypeEnum : xbbRefTypeEnums) {
                if (Objects.equals(xbbRefType, xbbRefTypeEnum.getCode())) {
                    return cache;
                }
            }
        }
        return UNKNOWN;
    }
    public static Boolean isSaasData(XbbRefTypeEnum xbbRefTypeEnum) {
        if (Objects.isNull(xbbRefTypeEnum)) {
            return false;
        }
        for (SaasTableCountTypeEnum cache : values()) {
            List<XbbRefTypeEnum> xbbRefTypeEnums = cache.getXbbRefTypeEnums();
            for (XbbRefTypeEnum xbbRef : xbbRefTypeEnums) {
                if (Objects.equals(xbbRefTypeEnum, xbbRef)) {
                    return true;
                }
            }
        }
        return false;
    }

}
